#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
    x = 0; int f = 1; char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
    for (; isdigit(c); c = getchar()) x =  (x << 3) + (x << 1) + (c ^ 48);
    x *= f;
}
#define ll long long
const int maxn = 1e6 + 10;
// open the freopen
int Q;
int n;
int a[maxn];
int pr[maxn], p[maxn];
int s[maxn];
struct node{
    ll d;
    int id;
}dp[maxn];
ll Get(int x, int l, int r){
    if (r < l) return 0;
    ll ret = 0;
    if (a[l] == a[x]) ret += a[l];
    if (a[r] == a[r + 1]) ret -= a[r];
    if (a[l] == a[l - 1]) ret -= a[l];
    ret += s[r] - s[l - 1];
    return ret;
}
void solve(){
    read(n);
    for (int i = 1; i <= n; i++) read(a[i]);
    for (int i = 1; i <= n; i++){
        s[i] = 0;
        dp[i].d = 0;
        dp[i].id = 0;
    }
    for (int i = 1; i <= n; i++){
        if (a[i] == a[i - 1]) s[i] = a[i];
    }
    for (int i = 1; i <= n; i++) s[i] += s[i - 1];
    for (int i = 1; i <= n; i++){
        for (int j = i - 1; j >= 1; j--){
            ll tmp = dp[j].d + Get(dp[j].id, j + 1, i - 1) + (a[i] == a[j] ? a[i] : 0);
            if (j == i - 1){
                dp[i].d = tmp;
                dp[i].id = dp[j].id;
                continue;
            }
            if (tmp > dp[i].d){
                dp[i].d = tmp;
                dp[i].id = i - 1;
            }
        }
    }
    printf("%lld\n", dp[n].d);
}
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    read(Q);
    while (Q--){
        solve();
    }
    return 0;
}
